home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programmierung
/
Power-Programmierung (Tewi)(1994).iso
/
magazine
/
spoc88
/
cflt20
/
tan.c
< prev
Wrap
Text File
|
1988-04-15
|
610b
|
28 lines
#define NUM_TERMS 15
double approx_tan(double x)
{
int i;
long double x2 = x*x, y = 0;
if (x == 0) return 0;
for (i = 2*NUM_TERMS-1; i >= 0; i -= 2)
y = i - x2 / y;
return x / y;
}
/* for _control87 */
#include <float.h>
/* for tan */
#include <math.h>
int cdecl main(int argc, char **argv)
{
double x, y;
/* mask all exceptions but denormal */
_control87(MCW_EM-EM_DENORMAL,MCW_EM);
x = 2.1;
y = tan(x);
printf("tan(%g) = %25.20g\n",x,y);
y = approx_tan(x);
printf("approx_tan(%g) = %25.20g\n",x,y);
}